/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.common.service;

import com.koron.common.bean.KpiStatisticsBean;
import com.koron.common.domain.KpiStatistics;
import com.koron.common.mapper.KpiStatisticsMapper;
import org.koron.ebs.mybatis.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class KpiStatisticsService {
	private final static Logger logger= LoggerFactory.getLogger(KpiStatisticsService.class);

	public int insert(KpiStatistics bean){
		try(SessionFactory sf = new SessionFactory()) {
			return sf.getMapper(KpiStatisticsMapper.class).insert(bean);
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
		}
		return 0;
	}
	
	public int batchInsert(List<KpiStatistics> beanList){
		try(SessionFactory sf = new SessionFactory()) {
			return sf.getMapper(KpiStatisticsMapper.class).batchInsert(beanList);
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
		}
		return 0;
	}
	
	public int delete(String kpiCode,String dateValue,String objectId){
		try(SessionFactory sf = new SessionFactory()) {
			return sf.getMapper(KpiStatisticsMapper.class).delete(kpiCode, dateValue, objectId);
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
		}
		return 0;
	}
	
	public List<KpiStatistics> query(KpiStatisticsBean bean){
		try(SessionFactory sf = new SessionFactory()) {
			return sf.getMapper(KpiStatisticsMapper.class).query(bean);
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
		}
		return new ArrayList<>();
	}
	
	public int count(KpiStatisticsBean bean){
		try(SessionFactory sf = new SessionFactory()) {
			return sf.getMapper(KpiStatisticsMapper.class).count(bean);
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
		}
		return 0;
	}
}
